<template>
  <!--结清案件池-->
  <section class="page company-manage">
    <data-form :model="queryModel" @onSearch="refreshData" :page="pageService" @handleResetForm="follFeedback">
      <template slot="inputs">
        <el-form-item label="借据号" prop="caseNumber">
            <el-input v-model="queryModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="批次号" prop="outBatch">
            <el-input v-model="queryModel.outBatch"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
            <el-input v-model="queryModel.personalName"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
            <el-input v-model="queryModel.mobileNo"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="idCard">
            <el-input v-model="queryModel.idCard  "></el-input>
        </el-form-item>
       <el-form-item label="地区" prop="area">
          <el-cascader v-model="queryModel.area" :options="$city.getCityData()" change-on-select clearable></el-cascader>
        </el-form-item>
        <el-form-item label="催收员" prop="currentCollector">
            <el-input v-model="queryModel.currentCollector"></el-input>
        </el-form-item>
         <el-form-item label="委外方" prop="outsName">
          <!-- <el-select v-model="queryModel.outsName" placeholder="请选择" clearable>
            <el-option v-for="item in outSourceList" :key="item.id" :label="item.outsName" :value="item.id"></el-option>
          </el-select> -->
          <select-department :specialOptions="specialOptions" v-model="queryModel.outName"></select-department>
        </el-form-item>
        <el-form-item label="案件金额" prop="outAmount">
            <!-- <el-input v-model="queryModel.ajje"></el-input> -->
          <number-range v-model="queryModel.outAmount"></number-range>
        </el-form-item>
        <el-form-item label="逾期阶段" prop="overduePeriod">
          <el-select v-model="queryModel.overduePeriod" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('OverduePeriodStatus')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="逾期天数" prop="overdueDays">
          <number-range v-model="queryModel.overdueDays"></number-range>
        </el-form-item>
        <el-form-item label="行动代码" prop="followupBack">
          <el-select v-model="queryModel.followupBack" placeholder="请选择" clearable>
            <el-option v-for="{name,id} in customDataDict.filter(v=>v.dataType==='FOLLOW_UP').filter(m=>m.name!=='行动代码')" :key="id" :label="name" :value="id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="流转来源" prop="turnSource">
          <el-select v-model="queryModel.turnSource" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('TurnSource').filter(m=>m.name!=='委外'&&m.name!=='API接口'&&m.name!=='Excel导入')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="系统来源" prop="sysCode">
          <el-select v-model="queryModel.sysCode" placeholder="请选择" clearable>
            <el-option v-for="{index,name,code} in $dict.getDictData('SysCode')" :key="index" :label="name" :value="code.replace(/M|\+/, '')"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
            <el-input v-model="queryModel.productName"></el-input>
        </el-form-item>
        <el-form-item label="案件流入时间" prop="followInTime">
          <el-date-picker type="daterange" :editable="false" v-model="queryModel.followInTime" placeholder="选择日期时间" clearable>
          </el-date-picker>
        </el-form-item>
      </template>
    </data-form>
    <data-box @onPageChange="refreshData" :selectionList.sync="selectionList"  :data="dataList" :page="pageService">
      <template slot="columns">
        <el-table-column label="借据号" :min-width="$helper.getColumnWidth(6)">
          <template slot-scope="scope">
            <a  @click="openExecutionPage(scope.row)">{{scope.row.caseNumber}}</a>
          </template>
        </el-table-column>
        <el-table-column prop="outBatch" label="批次号" :min-width="$helper.getColumnWidth(4)">
        </el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :formatter="(row)=>$filter.encryptPhone(row.mobileNo)" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" :formatter="(row)=>$filter.encryptIDCardFour(row.idCard)" :min-width="$helper.getColumnWidth(7)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="area" label="地区" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip :formatter="(row) => $city.getCityName(Number(row.area))">
        </el-table-column>
        <el-table-column prop="overdueAmount" label="案件金额（元）" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="overduePeriod" label="逾期阶段" :min-width="$helper.getColumnWidth(3)">
        </el-table-column>
        <el-table-column prop="overdueDays" label="逾期天数" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="sysCode" label="系统来源" :formatter="(row) => $filter.encryptSysCode(row.sysCode)" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="productName" label="产品名称" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <!-- <el-table-column prop="" label="顾客类型" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column> -->
        <el-table-column prop="turnSource" label="流转来源" :formatter="(row) => $filter.dictConvert(row.turnSource,'TurnSource')" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="followInTime" label="案件流入时间" :formatter="(row) => $filter.dateTimeFormat(row.followInTime)" :min-width="$helper.getColumnWidth(6)">
        </el-table-column>
          <el-table-column prop="followupBack" label="行动代码" :formatter="(row) => $filter.dictcustomConvert(row.followupBack)" :min-width="$helper.getColumnWidth(4)" show-overflow-tooltip>
        </el-table-column>
      </template>
    </data-box>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Auth, Layout, Dependencies } from "~/core/decorator";
import { OutsourceSettleManageService } from "~/services/domain-service/outsource-settle-manage.service";
import { PageService } from "~/utils/page.service";
import DataForm from "~/components/common/data-form.vue";
import DataBox from "~/components/common/data-box.vue";
import NumberRange from "~/components/common/number-range.vue";
import { CityService } from "~/utils/city.service";
import { SortService } from "~/utils/sort.service";
import { OpenExecutionData } from "~/config/types";
import {
  ApplyType,
  CASE_CHANNEL,
  CASE_HALT_CATEGORY
} from "~/config/enum.config";
import { Mutation, Getter, namespace, State } from "vuex-class";
import SelectDepartment from "~/components/business-component/select-department.vue";
import { OutsourceService } from "~/services/domain-service/outsource.service";
import { CommonService } from "~/utils/common.service";
const CollectionExecutionModule = namespace("collection-execution");

// @Auth(1005)
@Layout("workspace")
@Component({
  components: {
    DataForm,
    DataBox,
    NumberRange,
    SelectDepartment
  }
})
export default class SellteManageIndex extends Vue {
  @Dependencies(OutsourceSettleManageService)
  private OutsourceSettleManageService: OutsourceSettleManageService;
  @Dependencies(PageService)
  private pageService: PageService;
  @Dependencies(SortService)
  private sortService: SortService;
  @Dependencies(OutsourceService) private outsourceService: OutsourceService;
  @CollectionExecutionModule.Action
  private openCollectionExecution;
  @State
  private outSourceList;
  @State private customDataDict;

  private selectionList: any[] = [];
  private proinviceList: any[] = []; // 省
  private cityList: any[] = []; //市
  private specialOptions:any[] = []
  // form 查询表单参数
  private queryModel: any = {
    outBatch: "",
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    idCard: "",
    localAddress: "",
    currentCollector: "",
    overduePeriod: "",
    turnSource: "",
    FollowupBack: "",
    sysCode: "",
    productName: "",
    area: [],
    followupBack: "",
    outAmount: {
      outAmountMax: "",
      outAmountMin: ""
    },
    overdueDays: {
      overdueDaysMax: "",
      overdueDaysMin: ""
    },
    followInTime: [], //案件流入时间
    outName: ""
  };
  private dataList: any[] = [];
  private mounted() {
    this.refreshData();
    this.getProvinces();
    this.getOuterSource()
  }
  //获取省数据
  private getProvinces() {
    this.proinviceList = CityService.getCityData({ level: 1 });
  }

  //获取市
  private getCitys(provinceId) {
    if (this.queryModel.cityCode) {
      this.queryModel.cityCode = "";
    }
    this.cityList = this.$city.getCityData({ level: 1, id: provinceId }); // 城市列表
  }
  /**
   * 查询列表
   */
  private refreshData() {
    this.OutsourceSettleManageService.getCaseSettlePoolPageList(
      this.queryModel,
      this.pageService
    ).subscribe(data => {
      this.dataList = data;
      if(this.dataList){
          this.dataList.forEach(x=>{
            x.overduePeriod>12?x.overduePeriod = 'M12+':x.overduePeriod = 'M'+x.overduePeriod
          })
        }
    });
  }

  /**
   * 进入查看执行页
   */
  private openExecutionPage(row) {
    this.openCollectionExecution(
      new OpenExecutionData(row.id, row.caseNumber, CASE_CHANNEL.OUTER, true,true)
    );
  }

  //获取委外部门不包括律所
  private getOuterSource() {
    this.outsourceService.getOuterSource().subscribe(
      data =>{ this.specialOptions = CommonService.generateTreeData(data, {
        keyName: 'id',
        parentKeyName: 'parentId'
      })
      // data =>{console.log(data,"data")
    })
  }

  /**
   * 重置numberRange
   */
  private follFeedback() {
    this.queryModel.outAmount = { min: "", max: "" };
    this.queryModel.overdueDays = { min: "", max: "" };
    this.queryModel.proinviceCode = "";
    this.queryModel.cityCode = "";
  }
}
</script>

<style lang="less">
</style>


